#include "DirectoryEntryWithTree.h"

bool DirectoryEntryWithTree::AreFoldersTheSame(DirectoryEntryWithTree* target)
{
	DirectoryTree* sourceTree;
	DirectoryTree* targetTree;	
	bool areFoldersTheSame = false;
	int compare;

	
	sourceTree = Folder;
	targetTree = target->Folder;
	
	while (false == areFoldersTheSame)
	{
		areFoldersTheSame = ((sourceTree->Parent == NULL) && (targetTree->Parent == NULL));
		if (areFoldersTheSame)
		{
			break;
		}
		if ((sourceTree->Parent == NULL) || (targetTree->Parent == NULL))
		{
			break;
		}
		compare = DirectoryEntry::CompareFileNames(&(sourceTree->Folder), &(targetTree->Folder));
		if (compare != 0)
		{
			break;
		}
		sourceTree = sourceTree->Parent;
		targetTree = targetTree->Parent;
	}
	
	return areFoldersTheSame;
}
int DirectoryEntryWithTree::CompareFiles(const DirectoryEntryWithTree* item1, const DirectoryEntryWithTree* item2)
{
	return DirectoryEntry::SortCompare(item1->File, item2->File);
}